<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>正则表达式测试工具 - 在线工具集合</title>
    <script src="../utils/toast.js"></script>
    <link rel="stylesheet" href="../utils/styles.css">
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Poppins', sans-serif;
            background: linear-gradient(135deg, #0f0c29, #302b63, #24243e);
            min-height: 100vh;
            color: #fff;
            position: relative;
            overflow-x: hidden;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 20px;
        }

        .container {
            max-width: 800px;
            width: 100%;
            background: rgba(255, 255, 255, 0.1);
            backdrop-filter: blur(10px);
            border-radius: 16px;
            padding: 40px;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
        }

        .header {
            text-align: center;
            margin-bottom: 30px;
        }

        .header h1 {
            font-size: 2.5em;
            margin-bottom: 10px;
            background: linear-gradient(45deg, #00ff88, #00b4d8);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }

        .header p {
            color: rgba(255, 255, 255, 0.8);
            font-size: 1.1em;
        }

        .regex-section {
            background: rgba(255, 255, 255, 0.05);
            border-radius: 16px;
            padding: 30px;
            margin-bottom: 20px;
            border: 1px solid rgba(255, 255, 255, 0.1);
            box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
            display: flex;
            flex-direction: column;
            gap: 20px;
        }

        .input-area {
            margin-bottom: 20px;
        }

        .input-area label {
            display: block;
            margin-bottom: 10px;
            color: rgba(255, 255, 255, 0.9);
            font-size: 1em;
            font-weight: 500;
        }

        .input-area input[type="text"],
        .input-area textarea {
            width: 100%;
            padding: 10px;
            background: rgba(255, 255, 255, 0.1);
            border: 1px solid rgba(255, 255, 255, 0.2);
            border-radius: 8px;
            color: #fff;
            font-size: 1em;
            resize: vertical;
        }

        .action-buttons {
            display: flex;
            gap: 20px;
            justify-content: center;
            margin-top: 20px;
        }

        .action-btn {
            padding: 15px 30px;
            border: none;
            border-radius: 12px;
            background: linear-gradient(45deg, #00ff88, #00b4d8);
            color: #1a1a1a;
            font-size: 1.1em;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            box-shadow: 0 4px 15px rgba(0, 255, 136, 0.2);
            letter-spacing: 0.5px;
        }

        .action-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 25px rgba(0, 255, 136, 0.3);
        }

        .action-btn:disabled {
            opacity: 0.5;
            cursor: not-allowed;
            transform: none;
            box-shadow: none;
        }

        .result-area {
            background: rgba(255, 255, 255, 0.05);
            border-radius: 8px;
            padding: 20px;
            border: 1px solid rgba(255, 255, 255, 0.1);
            color: #00ff88;
            font-size: 1em;
            font-weight: 500;
        }

        @media (max-width: 768px) {
            .container {
                padding: 20px 10px;
            }

            .header h1 {
                font-size: 2em;
            }

            .action-buttons {
                flex-direction: column;
            }

            .action-btn {
                width: 100%;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <a href="../index.html" style="color: #00ff88; text-decoration: none; margin-bottom: 1rem; display: block;">← 返回首页</a>
        
        <div class="header">
            <h1>正则表达式测试工具</h1>
            <p>输入正则表达式和测试字符串，查看匹配结果</p>
        </div>

        <div class="regex-section">
            <div class="input-area">
                <label for="regexInput">正则表达式</label>
                <input type="text" id="regexInput" placeholder="输入正则表达式...">
            </div>

            <div class="input-area">
                <label for="testString">测试字符串</label>
                <textarea id="testString" placeholder="输入要测试的字符串..."></textarea>
            </div>

            <div class="action-buttons">
                <button class="action-btn" id="testBtn">测试正则表达式</button>
            </div>

            <div class="result-area" id="resultArea">
                匹配结果将显示在这里
            </div>
        </div>
    </div>

    <script>
        const regexInput = document.getElementById('regexInput');
        const testString = document.getElementById('testString');
        const testBtn = document.getElementById('testBtn');
        const resultArea = document.getElementById('resultArea');

        testBtn.addEventListener('click', () => {
            //去掉空白字符串
            const regexPattern = regexInput.value.trim();
            const testStr = testString.value.trim();

            try {
                const regex = new RegExp(regexPattern);
                const matches = testStr.match(regex);

                if (matches) {
                    resultArea.textContent = `匹配成功: ${matches.join(', ')}`;
                    resultArea.style.color = '#00ff88';
                } else {
                    resultArea.textContent = '没有匹配结果';
                    resultArea.style.color = '#ff4d4d';
                }
            } catch (error) {
                resultArea.textContent = `正则表达式错误: ${error.message}`;
                resultArea.style.color = '#ff4d4d';
            }
        });
    </script>
</body>
</html> 